package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    //地址列表
    List<AddressBook> findList(AddressBook addressBook);

    //添加地址
    @Insert("insert into address_book values " +
            "(null,#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void save(AddressBook addressBook);

    //将当前所有的地址设为非默认
    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    void updateByUserId(Long aLong);

    //将指定id地址设置为默认
    void update(AddressBook addressBook);

     //主键删除
    @Delete("delete from sky_take_out.address_book where id = #{id}")
    void deleteById(Long id);

    //根据id查询地址
    @Select("select * from sky_take_out.address_book where id = #{id}")
    AddressBook findById(Long id);


}
